<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2>今天天气很{{info}}</h2>
        <button @click="changeInfo">点我切换天气</button>

    </div>

    <script type="text/javascript">
        Vue.config.productionTip = false;//阻止vue在启动的时候生成生产提示

        const vm = new Vue({
            el:"#root",
            data:{
                isHot:true
            },
            computed:{
                info(){
                    return this.isHot?'hot':'cool';
                }
            },
            methods: {
                changeInfo(){
                    this.isHot = !this.isHot;
                }
            },
            watch:{
                //监视info
                info:{
                    //当被监视属性变化时，才调用handler函数
                    handler(newValue,oldValue){
                        console.log("info改变了",newValue,oldValue);
                    }
                }
            }
        })

        //另一中监视方法监视isHot
        vm.$watch("isHot",{
            immediate:true,
            handler(newValue,oldValue){
                console.log("isHot改变了",newValue,oldValue);
            }
        })
   </script>
</body>
</html>